# Tem SysInfo Module.
# MODULE VERSION: 0.1 (BETA)
# System Information Module (Linux, 2.6 kernel, most distributions)
# Commands executed:
# uptime
# uname -r
# cat /proc/cpuinfo 
# free -m -o


# Functions:
# .sysinfo 


class SysInfo_Module
	def initialize(command_handler, trigger, subject, parameters)
		@subject = subject
		@command_handler = command_handler
		@trigger = trigger
		@parameters = parameters # Not needed, but good practice.
		display_sysinfo()
	end
	
	def display_sysinfo()
		# These probably are nowhere near the best optimized ways to do this.
		@system_uptime = `uptime`
		@system_uptime_time = @system_uptime.match(/up(.*).[\s][0-9][0-9]\:/).captures[0].strip
		@system_uptime_load = @system_uptime.match(/average\:(.*)/).captures[0].strip 
		puts "1"
		@system_kernel = `uname -r`
		@system_cpuinfo = `cat /proc/cpuinfo`
		@system_cpuinfo_model = @system_cpuinfo.match(/model[\s]name[\s]+\:[\s]+(.*)[\n]/).captures[0] # This *REALLY* should be optimized..
		@system_cpuinfo_mhz = @system_cpuinfo.match(/cpu[\s]MHz[\s]+\:[\s]+(.*)[\n]/).captures[0]
		@system_meminfo = `free -m -o | grep Mem`
		@system_meminfo_total = @system_meminfo.match(/[\s]+([0-9]+)[\s]+/).captures[0]
		@system_meminfo_used = @system_meminfo.match(/[\s]+[0-9]+[\s]+([0-9]+)[\s]+/).captures[0]
		@command_handler.privmsg(@subject, "[SysInfo] Uptime: #{@system_uptime_time} Load Averages: #{@system_uptime_load} Kernel: #{@system_kernel}")
		@command_handler.privmsg(@subject, "[SysInfo] CPU Model: #{@system_cpuinfo_model} CPU MHz: #{@system_cpuinfo_mhz} Memory Total: #{@system_meminfo_total}mb Memory Used: #{@system_meminfo_used}mb")
	end
end

$Loaded_Modules["sysinfo"] = "SysInfo_Module"
